package com.bw.controller;

import com.bw.common.Result;
import com.bw.entity.LoginUser;
import com.bw.entity.UserMenu;
import com.bw.service.UserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("菜单路由相关")
@RestController
@Slf4j
public class AuthController {

    @Autowired
    UserService userService;

    /**
     * 获取当前用户菜单
     * @return
     */
    @RequestMapping("/getAuthMenu")
    public Result getAuthMenu(){
        //获取当前登录用户
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        log.info("user:{}",loginUser);
        Long userId = loginUser.getId();
        return  Result.ok(userService.getAuthMenu(userId));
    }

    /**
     * 获取当前用户路由
     * @return
     */
    @RequestMapping("/getAuthRouter")
    public Result getAuthRouter(){
        //获取当前登录用户
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        log.info("user:{}",loginUser);
        Long userId = loginUser.getId();
        return  Result.ok(userService.getAuthRouter(userId));
    }
}
